home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: signalLatch.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:59 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "threadstate.h"
- #include "thread_globals.h"
-
-
- void
- signalLatch (
-
- register LATCH *latch
- )
- {
-
- register TCB *tcb;
-
-
- TRACE(TR_LATCH, TR_LEVEL_1);
-
- /*
- * check the semaphore magic number
- */
- CHECK_LATCH_MAGIC(latch);
-
- /*
- * check to see what type of latch is held
- */
- if (latch->shareCount != 0) {
-
- /*
- * decrement the share count
- */
- latch->shareCount--;
-
- /*
- * check to see if the count is sane
- */
- SM_ASSERT(LEVEL_3, (latch->shareCount >= 0) && (latch->exclusiveFlag == 0));
-
- } else {
-
- /*
- * check to see that the exclusive flag is set
- */
- SM_ASSERT(LEVEL_3, latch->exclusiveFlag != 0);
-
- /*
- * release the exclusive latch
- */
- latch->exclusiveFlag = 0;
- }
-
- /*
- * now we must grant outstanding latch requests
- */
- while (LIST_NOT_EMPTY( &(latch->waitList) )) {
-
- /*
- * get a pointer to the next waiter
- */
- tcb = (TCB *) FIRST_LIST_ELEMENT( &(latch->waitList) );
- CHECK_TCB_MAGIC(tcb);
-
- /*
- * check for the type of latch requested
- */
- if (tcb->state == THREAD_SH_LATCH_WAIT) {
-
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("thread:%d in share wait", tcb->id));
-
- /*
- * check to see if there is an outstanding exclusive latch
- */
- if (latch->exclusiveFlag == 0) {
-
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("granting share latch thread:%d", tcb->id));
-
- /*
- * grant request
- */
- listDeq( &(latch->waitList) );
- latch->shareCount++;
- listEnq( &ReadyList, &(tcb->controlList) );
-
- } else {
-
- /*
- * cannot grant any more requests
- */
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("cannot grant more requests"));
- break;
- }
-
- } else if (tcb->state == THREAD_EX_LATCH_WAIT) {
-
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("thread:%d in exclusive wait", tcb->id));
-
- /*
- * check to see if there are any share or
- * exclusive latches granted
- */
- if ((latch->exclusiveFlag == 0) && (latch->shareCount == 0)) {
-
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("granting exclusive latch to:%d", tcb->id));
-
- /*
- * grant request
- */
- listDeq( &(latch->waitList) );
- latch->exclusiveFlag = 1;
- listEnq( &ReadyList, &(tcb->controlList) );
-
- /*
- * cannot grant any more requests
- */
- break;
-
- } else {
-
- /*
- * cannot grant any more requests
- */
- TRPRINT(TR_LATCH, TR_LEVEL_2, ("cannot grant more requests"));
- break;
- }
-
- } else {
-
- /*
- * this cannot happen
- */
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
- }
- }
-